﻿<cfscript>
/** 
* @hint "markManager - 学生成绩唯一性验证" 
*/ 

component 
	extends="MachII.framework.EventFilter" 
	displayname="acadmicManager.filters.senate.markUniqueFilter" 
	output=false
	depends="sequenceStudentMark"
	{
	
	/*
	* @hint "Configures this filter as part of the Mach-II framework" 
	*/
	public void function configure() output=false {} 
	
	/*
	* @hint "Filters event and returns a boolean to Mach-II indicating whether or not the event queue should proceed.  If not, the event queue is cleared and a new event is announced."
	* 
	* @event "MachII Event Object"
	* @eventContext "MachII EventContext Object"
	*/
	public boolean function filterEvent ( required MachII.framework.Event event, required MachII.framework.EventContext eventContext ) output=false {
		
		var sequenceStudentMark = getsequenceStudentMark();
		
		var courseId = event.getArg("CourseID");
		var studentId = event.getArg("StudentID");
		var taskType = event.getArg("TaskType");
		var termId = event.getArg("TermY") & event.getArg("TermT");
		
		sequenceStudentMark.setStudentID(studentId);
		sequenceStudentMark.setCourseID(courseId);
		sequenceStudentMark.setTermID(termId);
		sequenceStudentMark.setTaskType(taskType);
		
		var markId = sequenceStudentMark.getID();
				
		var sql = "SELECT 1 FROM t_student_mark WHERE scm_id = :markId "; 
		
		var queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="markId", value=markId, cfsqltype="cf_sql_varchar" );
		
		var rs_markChecker = queryObj.execute( sql=sql ).getResult();
		
		if ( rs_markChecker.recordCount EQ 0 ) {
			/* 如果成绩主键规则唯一 则继续更新 */
			return true;
		}
		else {
			/* 如果成绩主键重复 */
			event.setArg("markExistsID", markId);

			event.setArg("STU", studentId);
			event.setArg("CID", courseId);
			event.setArg("TID", termId);
			announceEvent("markExists", event.getArgs());
		}
		
		return false;
	}
	
}

</cfscript>